package cc.bukkitPlugin.banitem.listener;

import org.bukkit.entity.Player;
import org.bukkit.event.Listener;

import cc.bukkitPlugin.banitem.BanItem;
import cc.bukkitPlugin.banitem.check.CheckResult;
import cc.bukkitPlugin.banitem.check.ItemCheck;
import cc.bukkitPlugin.banitem.manager.PermissionMan;

public abstract class APreventListener implements Listener{

    protected BanItem mPlugin;
    protected CheckResult tCheckResult;
    private ItemCheck mItemChecker;
    private PermissionMan mPermissionMan;

    /**
     * 实例化一个监听器,会自己注册到监听列表
     */
    public APreventListener(BanItem pPlugin){
        this.mPlugin=pPlugin;
        this.mPlugin.getServer().getPluginManager().registerEvents(this,this.mPlugin);
    }

    protected ItemCheck getItemChecker(){
        if(this.mItemChecker==null){
            this.mItemChecker=this.mPlugin.getManager(ItemCheck.class);
        }
        return this.mItemChecker;
    }

    protected PermissionMan getPermissionMan(){
        if(this.mPermissionMan==null){
            this.mPermissionMan=this.mPlugin.getManager(PermissionMan.class);
        }
        return this.mPermissionMan;
    }

    protected void switchSlot(Player pPlayer){
        int itemslot=pPlayer.getInventory().getHeldItemSlot();
        pPlayer.getInventory().setHeldItemSlot((itemslot+1)%8);
    }

}
